# -*- coding: utf-8 -*-
# @Time    : 2024/7/3 14:00
# @Author  : floraachy
# @File    : common_page
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.base_utils.base_page import BasePage


class CommonPage(BasePage):
    """存放一些公共的元素和操作方法"""
    # 导航栏上的登录按钮
    locator_login_btn_on_nav = "xpath=//a[text()='登录']"
    # 登录弹窗
    locator_login_pop = "//div[@id='log_reg_content']"
    # 登录弹窗中的用户名输入框
    locator_username_input_on_pop = "xpath=//input[@name='username']"
    # 登录弹窗中的密码输入框
    locator_password_input_on_pop = "xpath=//input[@name='password']"
    # 登录弹窗中的登录按钮
    locator_login_btn_on_pop = "//div[text()='登录']"
    # 导航栏上的新建图标
    locator_new_icon_on_nav = "xpath=//div[contains(@class, 'head-right')]/img"
    # 新建项目按钮
    locator_new_project_btn = "xpath=//a[text()='新建项目']"
    # 确定按钮
    locator_confirm_btn = "xpath=//a[text()='确定']"
    # 是 按钮
    locator_yes_btn = "//span[text()='是']"
    # X 按钮
    locator_x_btn = "//span[@class='ant-modal-close-x']"
    # 确认删除按钮
    locator_confirm_delete_btn = "//span[text()='确认删除']/parent::button"
    # 系统通知弹窗
    locator_sys_notice_box = "//div[@class='sysBox']"
    # 系统通知弹窗，确认阅读按钮
    locator_confirm_read_btn = "//button/span[text()='确认并继续']"
    # 登录成功后头像处昵称
    locator_avatar_nickname = "xpath=//a[@class='ant-dropdown-trigger']"
    # 登录后提示未绑定手机号码
    locator_unbind_phone_tip = "//p[text()='请绑定手机号以获取平台更多短信服务及找回密码服务']"
    # 导航栏右侧弹窗提示语
    locator_tip_on_right_nav = "xpath=//div[@class='ant-notification-notice-description']"

    @allure.step("点击导航栏右上角的【登录】按钮，进入登录页面")
    def click_login_button_on_nav(self):
        """
        点击导航栏右上角的登录按钮，进入登录页面
        """
        self.click(locator=self.locator_login_btn_on_nav)

    @allure.step("弹窗登录：输入用户名：{login}")
    def input_username_on_pop(self, login):
        """
        弹窗登录：输入用户名
        """
        self.input(locator=self.locator_username_input_on_pop, text=login)

    @allure.step("弹窗登录：输入密码：{password}")
    def input_password_on_pop(self, password):
        """
        弹窗登录：输入密码
        """
        self.input(locator=self.locator_password_input_on_pop, text=password)

    @allure.step("弹窗登录：点击【登录】按钮，提交登录表单")
    def submit_login_on_pop(self):
        """
        弹窗登录：点击登录按钮，提交登录表单
        """
        self.click(locator=self.locator_login_btn_on_pop)

    @allure.step("点击导航栏右上角的【新建】图标")
    def click_new_icon(self):
        """
        点击导航栏右上角的新建图标
        """
        self.click(locator=self.locator_new_icon_on_nav)

    @allure.step("点击新建图标下的【新建项目】按钮，进入新建项目页面")
    def click_new_project_button(self):
        """
        点击新建图标下的新建项目按钮，进入新建项目页面
        """
        self.click(locator=self.locator_new_project_btn)

    @allure.step("点击【确定】按钮")
    def click_confirm_button(self):
        """
        点击"确定”按钮
        """
        self.click(self.locator_confirm_btn)
        self.page.wait_for_timeout(3000)

    @allure.step("点击【是】按钮")
    def click_yes_button(self):
        """
         点击"是”按钮
        """
        self.click(self.locator_yes_btn)
        self.page.wait_for_timeout(3000)

    @allure.step("点击【x】按钮")
    def click_x_button(self):
        """
         点击"X”按钮
        """
        self.click(self.locator_x_btn)
        self.page.wait_for_timeout(3000)

    @allure.step("点击【确认删除】按钮")
    def click_confirm_delete_button(self):
        """
         点击'确认删除'按钮
        """
        self.click(self.locator_confirm_delete_btn)
        self.page.wait_for_timeout(3000)

    @allure.step("关闭系统通知弹窗")
    def close_sys_notice_box(self):
        """
        关闭系统通知弹窗
        """
        if len(self.get_all_elements(self.locator_sys_notice_box)) > 0:
            self.click(locator=self.locator_confirm_read_btn)

    # ----------------------------- 流程 ----------------------------
    def login_on_pop_flow(self, login, password):
        """
        完整登录操作 --> 弹窗登录：输入用户名，密码，点击登录按钮，提交登录表单
        """
        self.input_username_on_pop(login)
        self.input_password_on_pop(password)
        self.submit_login_on_pop()
        self.page.wait_for_timeout(1000)
